using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[Serializable]
[ExecuteInEditMode]
public class replaceFonts : MonoBehaviour
{
	public Font _baseFont;

	public TMP_FontAsset _TMProFont;

	public List<GameObject> objects = new List<GameObject>();

	[SerializeField]
	public List<Text> uiText = new List<Text>();

	[SerializeField]
	public List<TextMeshProUGUI> meshText = new List<TextMeshProUGUI>();

	[SerializeField]
	public List<TextMeshPro> meshText1 = new List<TextMeshPro>();

	public List<string> path = new List<string>();

	public List<GameObject> o = new List<GameObject>();

	[ContextMenu("Do Something")]
	public void Find()
	{
		uiText.Clear();
		meshText.Clear();
		meshText1.Clear();
		objects.Clear();
		objects.AddRange(SceneManager.GetActiveScene().GetRootGameObjects());
		for (int i = 0; i < objects.Count; i++)
		{
			if (objects[i].TryGetComponent<Text>(out var component))
			{
				uiText.Add(component);
			}
			if (objects[i].TryGetComponent<TextMeshProUGUI>(out var component2))
			{
				meshText.Add(component2);
			}
			if (objects[i].TryGetComponent<TextMeshPro>(out var component3))
			{
				meshText1.Add(component3);
			}
			uiText.AddRange(FinderDeepChildren.FindDeepChildNoTag<Text>(objects[i].transform));
			meshText.AddRange(UnityEngine.Object.FindObjectsOfType<TextMeshProUGUI>(objects[i].transform));
			meshText1.AddRange(UnityEngine.Object.FindObjectsOfType<TextMeshPro>(objects[i].transform));
		}
		for (int num = uiText.Count - 1; num >= 0; num--)
		{
			if (uiText[num].font == null)
			{
				uiText[num].font = _baseFont;
			}
		}
		for (int num2 = meshText.Count - 1; num2 >= 0; num2--)
		{
			if (meshText[num2].font == null)
			{
				meshText[num2].font = _TMProFont;
			}
		}
		for (int num3 = meshText1.Count - 1; num3 >= 0; num3--)
		{
			if (meshText1[num3].font == null)
			{
				meshText1[num3].font = _TMProFont;
			}
		}
	}

	[ContextMenu("Prefab acting")]
	private void FindInPrefab()
	{
		uiText.Clear();
		meshText.Clear();
		meshText1.Clear();
		objects.Clear();
		objects.Add(base.gameObject.transform.parent.gameObject);
		for (int i = 0; i < objects.Count; i++)
		{
			if (objects[i].TryGetComponent<Text>(out var component))
			{
				uiText.Add(component);
			}
			if (objects[i].TryGetComponent<TextMeshProUGUI>(out var component2))
			{
				meshText.Add(component2);
			}
			if (objects[i].TryGetComponent<TextMeshPro>(out var component3))
			{
				meshText1.Add(component3);
			}
			uiText.AddRange(FinderDeepChildren.FindDeepChildNoTag<Text>(objects[i].transform));
			meshText.AddRange(FinderDeepChildren.FindDeepChildNoTag<TextMeshProUGUI>(objects[i].transform));
			meshText1.AddRange(FinderDeepChildren.FindDeepChildNoTag<TextMeshPro>(objects[i].transform));
		}
		for (int j = 0; j < uiText.Count; j++)
		{
			uiText[j].font = null;
			uiText[j].font = _baseFont;
		}
		for (int k = 0; k < meshText.Count; k++)
		{
			meshText[k].font = _TMProFont;
		}
		for (int l = 0; l < meshText1.Count; l++)
		{
			meshText1[l].font = _TMProFont;
		}
	}
}
